package com.ruoyi.asset.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.asset.domain.AstToolList;
import com.ruoyi.asset.service.IAstToolListService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工具清单Controller
 * 
 * @author xunzhe
 * @date 2024-12-02
 */
@Controller
@RequestMapping("/asset/astToolList")
public class AstToolListController extends BaseController
{
    private String prefix = "asset/astToolList";

    @Autowired
    private IAstToolListService astToolListService;

    @RequiresPermissions("asset:astToolList:view")
    @GetMapping()
    public String astToolList()
    {
        return prefix + "/astToolList";
    }

    /**
     * 查询工具清单列表
     */
    @RequiresPermissions("asset:astToolList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AstToolList astToolList)
    {
        startPage();
        List<AstToolList> list = astToolListService.selectAstToolListList(astToolList);
        return getDataTable(list);
    }

    /**
     * 导出工具清单列表
     */
    @RequiresPermissions("asset:astToolList:export")
    @Log(title = "工具清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AstToolList astToolList)
    {
        List<AstToolList> list = astToolListService.selectAstToolListList(astToolList);
        ExcelUtil<AstToolList> util = new ExcelUtil<AstToolList>(AstToolList.class);
        return util.exportExcel(list, "工具清单数据");
    }

    /**
     * 新增工具清单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工具清单
     */
    @RequiresPermissions("asset:astToolList:add")
    @Log(title = "工具清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AstToolList astToolList)
    {
        return toAjax(astToolListService.insertAstToolList(astToolList));
    }

    /**
     * 修改工具清单
     */
    @RequiresPermissions("asset:astToolList:edit")
    @GetMapping("/edit/{toolId}")
    public String edit(@PathVariable("toolId") Long toolId, ModelMap mmap)
    {
        AstToolList astToolList = astToolListService.selectAstToolListByToolId(toolId);
        mmap.put("astToolList", astToolList);
        return prefix + "/edit";
    }

    /**
     * 修改保存工具清单
     */
    @RequiresPermissions("asset:astToolList:edit")
    @Log(title = "工具清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AstToolList astToolList)
    {
        return toAjax(astToolListService.updateAstToolList(astToolList));
    }

    /**
     * 删除工具清单
     */
    @RequiresPermissions("asset:astToolList:remove")
    @Log(title = "工具清单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(astToolListService.deleteAstToolListByToolIds(ids));
    }
}
